package cn.bai.mvc;

import java.util.List;

/**
 * Created by Admin on 12/23 0023.
 */
public class CustomerDaoImp extends DaoImp<Customer> implements CustomerDao {
    @Override
    public List<Customer> getForListWithCriteriaCustomer(CriteriaCustomer cc) {
        String sql="select * from customer where name like ? and address like ? and phone like ?";
        return getList(sql,cc.getName(),cc.getAddress(),cc.getPhone());
    }

    @Override
    public List<Customer> getAll() {
        String sql="select * from customer";
        return getList(sql);
    }

    @Override
    public void save(Customer customer) {
        String sql="insert into customer (name,address,phone) values (?,?,?)";
        update(sql,customer.getName(),customer.getAddress(),customer.getPhone());
    }

    @Override
    public Customer get(Integer id) {
        String sql="select * from customer where id=?";
        return get(sql,id);
    }

    @Override
    public void delete(Integer id) {
        String sql="delete from customer where id=?";
        update(sql,id);
    }

    @Override
    public void update(Customer customer) {
        String sql="update customer set name=? ,address=? , phone=? where id=?";
        update(sql,customer.getName(),customer.getAddress(),customer.getPhone(),customer.getId());
    }

    @Override
    public long getCountWithName(String name) {
        String sql="select count(id) from customer where name=? ";
        return getForValue(sql,name);
    }
}
